package com.dwd.hrm.controller;

import com.dwd.hrm.domain.SendSmsDto;
import com.dwd.hrm.service.IVerifycodeService;
import com.dwd.hrm.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * @Description: TODO
 * @Author 汶狄
 * @Date 2021/3/11 14:09
 * @Version 1.0
 */
@RestController
@RequestMapping("/verifycode")
public class VerifycodeController {
    @Autowired
    private IVerifycodeService verifycodeService;

    /**
     * 获取图片验证码
     *
     * @param key
     * @return
     */
    @GetMapping("imageCode/{key}")
    public AjaxResult imageCode(@PathVariable("key") String key) throws IOException {
        String base64 = verifycodeService.imageCode(key);
        return AjaxResult.me().setResultObj(base64);
    }

    /**
     * 手机验证码
     *
     * @param sendSmsDto
     * @return
     */
    @PostMapping("sendSmsCode")
    public AjaxResult sendSmsCode(@RequestBody SendSmsDto sendSmsDto) {
        verifycodeService.sendSmsCode(sendSmsDto);
        return AjaxResult.me();
    }
}
